package com.example.ecas.persistence;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.ecas.pojo.Abstracts;
import com.example.ecas.pojo.WcRpat;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.stereotype.Repository;

@Repository
@Mapper
public interface AbstractsMapper extends BaseMapper<Abstracts> {

    default Abstracts getAbstract(int caseId) {
        return this.selectById(caseId);
    }

    default int addAbstracts(Abstracts abstracts) {
        if (abstracts == null) {
            return 0;
        }
        QueryWrapper<Abstracts> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("case_id", abstracts.getCaseId());
        if (!this.exists(queryWrapper)) {
            return this.insert(abstracts);
        }
        return 0;
    }
}
